[HEADER]
	VERSION		00.00.00.00
	DESCRIPTION Phong Lighting Example
	COPYRIGHT	Imagination Technologies Ltd.
[/HEADER]

[TEXTURES]
[/TEXTURES]

[VERTEXSHADER]
	NAME myVertShader
	[GLSL_CODE]
		attribute highp vec4	myVertex;
		attribute mediump vec3	myNormal;
		uniform mediump mat4	myMVPMatrix;
		uniform mediump mat3	myModelViewIT;
		uniform mediump mat4	myModelView;

		const mediump vec4	LightSourcePosition = vec4(-1.0, 3.0, -2.0, 0.0);
		const mediump vec4	ambient = vec4(0.2,0.2,0.2,1.0); 
		const mediump vec4	ambientGlobal = vec4(0.2,0.2,0.2,1.0);
		const mediump vec4	diffuse = vec4(0.3,0.4,0.1,1.0); 
		 
		varying mediump vec4 color; 

		void main()
		{
			vec4 ecPos;
			mediump vec3 viewV,ldir;
			mediump float NdotL,NdotHV;
			mediump vec3 normal,lightDir,halfVector;
			
			// Transform the position
			gl_Position = myMVPMatrix * myVertex;
			
			// Transform the normal
			normal = normalize(myModelViewIT * myNormal);
			
			// Compute the light's direction 
			ecPos = myModelView * myVertex;
			lightDir = normalize(vec3(LightSourcePosition-ecPos));

			halfVector = normalize(lightDir + vec3(ecPos));
				
			/* The ambient terms have been separated since one of them */
			/* suffers attenuation */
			color = ambientGlobal; 
			
			/* compute the dot product between normal and normalized lightdir */
			NdotL = abs(dot(normal,lightDir));

			if (NdotL > 0.0) 
			{
				color += (diffuse * NdotL + ambient);	
				
				NdotHV = abs(dot(normal,halfVector));
				color += vec4(0.6,0.2,0.4,1.0) * pow(NdotHV,50.0);
			}
		}
	[/GLSL_CODE]
[/VERTEXSHADER]

[FRAGMENTSHADER]
	NAME myFragShader
	[GLSL_CODE]

	varying mediump vec4 color;

		void main()
		{
			gl_FragColor = color;
		}
	[/GLSL_CODE]
[/FRAGMENTSHADER]

[EFFECT]
	NAME myEffect

	ATTRIBUTE	myVertex			POSITION
	ATTRIBUTE	myNormal			NORMAL
	UNIFORM		myMVPMatrix			WORLDVIEWPROJECTION
	UNIFORM		myModelView			WORLDVIEW
	UNIFORM		myModelViewIT		WORLDVIEWIT

	VERTEXSHADER myVertShader
	FRAGMENTSHADER myFragShader
[/EFFECT]
